package fr.ensisa.sunspot.actor.writer;

import fr.ensisa.sunspot.actor.writer.strategy.IWriteStrategy;
import fr.ensisa.sunspot.actor.AbstractActor;
import fr.ensisa.sunspot.actor.IActor;
import fr.ensisa.sunspot.event.IEvent;
/**
 *
 * @author Michel Hassenforder
 */

public class StrategicWriter extends AbstractActor {

    private IWriteStrategy strategy;

    public StrategicWriter () {
        super(IActor.KIND_WRITER);
        this.strategy = null;
    }

    public void setActivated (boolean activated) {
        super.setActivated(activated);
        strategy.setActivated(activated);
    }

    public int getID() {
        return 1;
    }

    public int process(long timeStamp, IEvent incomingEvent) {
    	if (incomingEvent == null) return IActor.RETURN_DONOTHING;
        if (getStrategy() != null)
        	getStrategy().write (timeStamp, incomingEvent);
        return IActor.RETURN_DONOTHING;
    }

    public void setTemplate(int major, int minor, int state) {
        super.setTemplate(major, minor, state);
    }

    /**
     * @return the strategy
     */
    public IWriteStrategy getStrategy() {
        return strategy;
    }

    /**
     * @param strategy the strategy to set
     */
    public void setStrategy(IWriteStrategy strategy) {
        this.strategy = strategy;
    }

}
